<template>
  <div>
      <div class="main">
          <div class="film">
              <div :class="{'film-header':true,'bg':isShow}">
                  <div class="goback" @click="go()">
                      <img src="@/assets/goback.png" alt="">
                  </div>
                  <div class="title">
                      {{detaiList.name}}
                  </div>
              </div>
              <div class="film-poster" style="height: 56vw;">
                  <div class="img-wrap" style="height:100%">
                      <img :src="detaiList.poster" alt="">
                  </div>
              </div>
              <div class="film-detail">
                  <div class="col">
                      <div class="film-name">
                          <span class="name">{{detaiList.name}}</span>
                          <span class="item">{{detaiList.filmType&&detaiList.filmType.name}}</span>
                      </div>
                      <div class="film-grade">
                          <span class="grade">{{detaiList.grade}}</span>
                          <span class="grade-text">分</span>
                      </div>
                  </div>
                    <div class="category">{{detaiList.category}}</div>
                    <div class="runtime">{{new Date(parseInt(detaiList.premiereAt) * 1000).toLocaleString().slice(0,9).replace('/', '-').replace('/', '-') + '上映'}}</div>
                    <div class="film-nation">{{detaiList.nation}}|{{detaiList.runtime+"分钟"}}</div>
                    <div :class="{'test':true, 'film-nation':true, 'hidde':flag}">{{detaiList.synopsis}}</div>
                    <div class="toggle" @click="show">
                        <img src="@/assets/toggle.png" alt="">
                    </div>
              </div>
              <div class="actors">
                  <div class="actors-title">
                      <span class="actors-title-text">演职演员</span>
                  </div>
                  <div class="actors-list">
                      <ul class="item-nav">
                          <li class="scroll-item" v-for= "(p,index) in detaiList.actors" :key="index">
                              <div class="actor-item">
                                  <div class="actor-img">
                                      <div class="img-wrap">
                                          <img :src="p.avatarAddress" alt="">
                                      </div>
                                      <span class="actors-name">{{p.name}}</span>
                                      <span class="actor-role">{{p.role}}</span>
                                  </div>
                              </div>
                          </li>
                      </ul>
                  </div>
              </div>
              <div class="photos">
                  <div class="photos-title">
                      <span class="photos-title-text">剧照</span>
                      <span class="photos-to-all">全部(5)
                          <i class="iconfont icon-ico_listarrow"></i>
                      </span>
                  </div>
                  <div class="photos-list">
                      <ul class="items-nav">
                          <li class="photos-item-wrap" v-for="(pic,index) in detaiList.photos" :key="index">
                              <div class="photos-item">
                                  <div class="img-wrap">
                                      <img :src="pic" alt="">
                                  </div>
                              </div>
                          </li>
                      </ul>
                  </div>
              </div>
              <a href="javascript:;" class="buy-btn" @click="gocinema(detaiList.filmId)">
                  <div class="gobuy">
                      选座购票
                  </div>
              </a>
          </div>
      </div>
  </div>
</template>

<script>
import '@/assets/all/iconfont.css'
import {getDetail} from '@/api'
export default {
    data() {
        return {
            detaiList:[],
            id:'',
            flag:true,
            isShow : false
        }
    },
    watch: {
        $route:{
            handler(n,o){
                this.id = n.params.id
                this.getData(this.id)
            },
            deep:true,
            immediate:true

        }
    },
    created() {
        this.tofix()
        console.log(this.detaiList)
    },
    methods: {
        getData(id){
            getDetail(id).then(res=>{
                this.detaiList = res.data.data.film
            })
        },
        go(){
            this.$router.go(-1)
        },
        show(){
            this.flag=!this.flag
        },
        tofix(){
            window.addEventListener("scroll",()=>{
                var top =document.documentElement.scrollTop||document.body.scrollTop;
                if(top <80){
                this.isShow=false;
                document.querySelector('.title').style.opacity=0
                }else{
                this.isShow=true;
                document.querySelector('.title').style.opacity=1
                }
          })
    },
    gocinema(cinemaid){
        this.$router.push('/cinemas/'+cinemaid)
    }
        
    },

}
</script>

<style lang="scss" scoped>
    *{
        margin: 0;
        padding: 0;
        box-sizing:border-box;
    }
    .bg{
         background: #fff;
         border-bottom: 1px solid #ededed;
    }
    
    .main{
        height: 100%;
        .film-header{
            position: fixed;
            // background-color: hsla(0,0%,100%,0);
            color: transparent;
            transition: all .3s ease;
            width: 100vw;
            height: 44px;
            z-index: 1;
            transition: all .3s ease;
            // background-color: #fff;
            color: #191a1b;
            .goback {
                height: 30px;
                position: absolute;
                top: 5px;
                left: 5px;
                img {
                    width: 30px;
                    }
                }
            .title{
                font-size: 17px;
                line-height: 44px;
                width: 100vw;
                text-align: center;
                }
            }
            .film-header:after {
                content: " ";
                position: absolute;
                left: 0;
                bottom: 0;
                right: 0;
                height: 1px;
                // border-bottom: 1px solid #ededed;
                color: #ededed;
                transform-origin: 0 100%;
                transform: scaleY(.5);
                }
                .film-poster{
                    width: 100%;
                    background: rgb(249, 249, 249);
                    position: relative;
                    .img-wrap{
                        width: 100%;
                        background: rgb(249, 249, 249);
                        opacity: 1;
                        display: block;
                        width: 100%;
                        background: #fff;
                        position: absolute;
                        overflow: hidden;
                        top: 0;
                        img{
                            width: 100%;
                            position: absolute;
                            top: 50%;
                            transform: translateY(-50%);
                            left: 0;
                    }
                }
            }
            .film-detail {
                padding: 15px;
                padding-top: 12px;
                padding-right: 15px;
                padding-bottom: 15px;
                padding-left: 15px;
                padding-top: 12px;
                background-color: #fff;
                .col {
                    display: -ms-flexbox;
                    display: flex;
                    justify-content: flex-start;
                    align-items: center;
                
                .film-name {
                    width: 256px;
                    span {
                        vertical-align: middle;
                    }
                    .name {
                        color: #191a1b;
                        font-size: 18px;
                        height: 24px;
                        line-height: 24px;
                        margin-right: 7px;
                    }
                    .item {
                        font-size: 9px;
                        color: #fff;
                        background-color: #d2d6dc;
                        height: 14px;
                        line-height: 14px;
                        padding: 0 2px;
                        border-radius: 2px;
                        display: inline-block;
                    }
                }
                .film-grade {
                    width: calc(100% - 250px);
                    text-align: right;
                    color: #ffb232;
                    .grade {
                        font-size: 18px;
                        font-style: italic;
                    }
                    .grade-text {
                        font-size: 10px;
                    }
                }
            }
            .category{
                font-size: 13px;
                color: #797d82;
                margin-top: 4px;
            }
            .runtime{
                font-size: 13px;
                color: #797d82;
                margin-top: 4px;
            }
            .film-nation{
                font-size: 13px;
                color: #797d82;
                margin-top: 4px;
            }
            .test {
                height: 154px;
                transition: height .5s ease;
                margin-top: 12px;
                font-size: 13px;
                color: #797d82;
            }
            .hidde {
                height: 38px!important;
                overflow: hidden;
            }
            .toggle{
                text-align: center;
                display: block;
                height: auto;
                width: 20px;
                margin: auto;
                line-height: normal;
                 img {
                    width: 8px;
                    margin: auto;
                }
            }
        }
        .actors {
            margin-top: 10px;
            background-color: #fff;
            .actors-name {
                margin-top: 24px;
                font-size: 12px;
                color: #191a1b;
                width: 85px;
                height: 18px;
                display: block;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
            .actor-role {
                font-size: 10px;
                color: #797d82;
            }
            .actors-title {
                width: 100%;
                padding: 15px;
                span {
                    display: inline-block;
                    height: 22.5px;
                    line-height: 22px;
                }
                .actors-title-text {
                    font-size: 16px;
                    text-align: left;
                    color: #191a1b;
                }
            }
            .actors-list{
                height: 140px;
                background: rgb(255, 255, 255);
                overflow-x: auto;
                overflow-y: hidden;
                // height: 236px;
                ul {
                    margin: 0;
                    padding-left: 15px;
                    list-style: none;
                    .scroll-item{
                        width: 85px;
                        min-width: 85px;
                        position: relative;
                        margin-right: 10px;
                        cursor: pointer;
                        display: block;
                        float: left;
                        .actor-item{
                            text-align: center;
                            span {
                                display: block;
                                text-align: center;
                            }
                            .actor-img{
                                width: 85px;
                                height: 85px;
                                background: rgb(249, 249, 249);
                                position: relative;
                                .img-wrap{
                                    width: 85px;
                                    height: 85px; 
                                    background: rgb(249, 249, 249);
                                    opacity: 1;
                                    display: block;
                                    img {
                                        width: 100%;
                                        position: absolute;
                                        top: 50%;
                                        transform: translateY(-50%);
                                        left: 0;
                                    }
                                }
                            }
                        }
                    }
                    .scroll-item:before {
                        content: "";
                        display: table;
                    }
                    .scroll-item:after{
                        content: "";
                        display: table;
                        clear: both;
                    }
                }
                .item-nav {
                    display: flex;
                    justify-content: flex-start;;
                    align-items: center;
                    position: relative;
                    width: 100%;
                }
                ul:before {
                    content: "";
                    display: table;
                }
                ul:after{
                        content: "";
                        display: table;
                        clear: both;
                    }

            }
        }
        .photos{
            margin-top: 10px;
            margin-bottom: 60px;
            background-color: #fff;
            .photos-title{
                height: 62px;
                width: 100%;
                padding: 15px;
                span {
                    display: inline-block;
                    height: 22.5px;
                    line-height: 22px;
                }
                .photos-title-text {
                    font-size: 16px;
                    text-align: left;
                    color: #191a1b;
                }
                .photos-to-all {
                    font-size: 13px;
                    color: #797d82;
                    float: right;
                    i{
                        font-size: 13px;
                    }
                }
            }
            .photos-list{
                height: 115px;
                background: rgb(255, 255, 255);
                overflow-x: auto;
                overflow-y: hidden;
                .items-nav {
                    display: flex;
                    justify-content: flex-start;
                    align-items: center;
                    position: relative;
                    width: 100%;
                    margin: 0;
                    padding-left: 15px;
                    list-style: none;
                    .photos-item-wrap{
                        min-width: 150px;
                        position: relative;
                        margin-right: 10px;
                        width: auto!important;
                        cursor: pointer;
                        display: block;
                        float: left;
                        .photos-item{
                            width: 150px;
                            height: 100px;
                            background: rgb(249, 249, 249);
                            position: relative;
                            .img-wrap{
                                width: 150px;
                                height: 100px;
                                background: rgb(249, 249, 249);
                                opacity: 1;
                                display: block;
                                position: absolute;
                                overflow: hidden;
                                top: 0;
                                img{
                                    width: 100%;
                                    position: absolute;
                                    // top: 50%;
                                    left: 0;
                                }
                            }
                        }
                    }
                    .photos-item-wrap:before{
                        content: "";
                        display: table;
                    }
                    .photos-item-wrap:after{
                        content: "";
                        display: table;
                        clear: both;
                    }
                }
                ul:before {
                    content: "";
                    display: table;
                }
                ul:after{
                        content: "";
                        display: table;
                        clear: both;
                    }
            }
        }
        .buy-btn{
            height: 49px;
            position: fixed;
            bottom: 0px;
            width: 100%;
            .gobuy{
                position: fixed;
                bottom: 0;
                left: 0;
                height: 49px;
                width: 100%;
                text-align: center;
                background-color: #ff5f16;
                color: #fff;
                font-size: 16px;
                line-height: 49px;
            }  
        }
        .buy-btn:focus,.buy-btn:hover{
            color: #333;
            text-decoration: none;
        }
    }

</style>